package com.game.protobuf;


import com.game.cluster.ClusterMessage;
import com.game.net.Connect;
import com.game.net.NetAddress;
import com.game.net.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PFSession extends Session<Object, ClusterMessage> {
    public static Logger log = LoggerFactory.getLogger(PFSession.class);

    public long userId;

    public String gatePath;

    public int workId;

    public long activeTime;

    public PFSession(String sessionId, Connect connect, NetAddress address) {
        super(sessionId, connect, address);
        this.activeTime = System.currentTimeMillis();
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public String getGatePath() {
        return this.gatePath;
    }

    public void setGatePath(String gatePath) {
        this.gatePath = gatePath;
    }

    public int getWorkId() {
        return this.workId;
    }

    public void setWorkId(int workId) {
        this.workId = workId;
    }

    public long getActiveTime() {
        return this.activeTime;
    }

    public void setActiveTime(long activeTime) {
        this.activeTime = activeTime;
    }

    public void send(Object msg) {
        PFMessage pfMessage;
        if (msg instanceof PFMessage) {
            pfMessage = (PFMessage)msg;
        } else {
            pfMessage = MessageUtil.getPFMessage(msg);
        }
        if (pfMessage != null) {
            ClusterMessage clusterMessage = new ClusterMessage(this.sessionId, pfMessage);
            this.connect.write(clusterMessage);
        }
    }

    public void send2Gate(Object msg) {
        PFMessage pfMessage = MessageUtil.getPFMessage(msg);
        ClusterMessage clusterMessage = new ClusterMessage(pfMessage);
        this.connect.write(clusterMessage);
    }

//    public void verifyPass(long userId, String ip, Object reference) {
//        this.reference = reference;
//        this.userId = userId;
//        SessionVerifyPass sessionVerifyPass = new SessionVerifyPass();
//        sessionVerifyPass.userId = userId;
//        sessionVerifyPass.sessionId = this.sessionId;
//        sessionVerifyPass.ip = ip;
//        sessionVerifyPass.create = System.currentTimeMillis();
//        PFMessage pfMessage = MessageUtil.getPFMessage(sessionVerifyPass);
//        ClusterMessage clusterMessage = new ClusterMessage(pfMessage);
//        this.connect.write(clusterMessage);
//    }

    public void onClose() {
        this.sessionListener.onSessionClose(this);
    }
}